//
//  rightNewShopTableViewCell.m
//  1243
//
//  Created by 杨森 on 16/4/19.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "rightNewShopTableViewCell.h"

@interface rightNewShopTableViewCell()

@property(nonatomic,strong)NSArray *menuArray;
@end


@implementation rightNewShopTableViewCell


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier menuArray:(NSArray *)menuArray
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.menuArray = menuArray;
        
    }
    return self;
  
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat margin = 10;
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(margin,margin, self.width - margin *2, self.height - margin *2)];
    backgroundView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:backgroundView];
    
    CGFloat ViewWidth = self.size.width / 6;
    CGFloat ViewHeight = self.size.width / 5;
    NSInteger queue = 3;
    CGFloat marginW = (self.width - 3*ViewWidth) / (queue);
    NSInteger count = 12;
    for (int i = 0; i < count; ++i) {
        
        int row = i / queue;//行号
        int loc = i % queue;//列号
        CGFloat viewx=  (marginW + ViewWidth) * loc + margin;
        CGFloat viewy=  (marginW +  ViewWidth) * row + margin +10 ;
        
        UIImageView *menuView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"beidahuang_%d",i+1]]];
        
        menuView.tag = 100 + i;
        menuView.frame = CGRectMake(viewx, viewy,ViewWidth, ViewHeight);
        menuView.contentMode = UIViewContentModeScaleAspectFit;
        
        [backgroundView addSubview:menuView];
        menuView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recognizerClick:)];
        [menuView addGestureRecognizer:recognizer];
        
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor grayColor];
        label.textAlignment = NSTextAlignmentCenter;
//        
//        NSString *string = [self.menuArray[i] objectForKey:@"Name"];
        label.text = [NSString stringWithFormat:@"%@",self.menuArray[i]];
        label.font = [UIFont systemFontOfSize:12];
        [backgroundView addSubview:label];
        
        label.frame = CGRectMake(viewx,CGRectGetMaxY(menuView.frame)+10, ViewWidth, 20);
    }
}

- (void)recognizerClick:(UITapGestureRecognizer *)recognizer
{
    if ([self.delegate respondsToSelector:@selector(rightNewShopDelegateDidSelectedAtIndex:)]) {
        
        [self.delegate rightNewShopDelegateDidSelectedAtIndex:recognizer.view.tag];
    }

}

@end
